//一般直接写在一个js文件中
layui.use(['element','form','laydate','upload'],function () {
    var form = layui.form,
        upload = layui.upload,
        laydate = layui.laydate;
    //选择老人
    $("#elderlyName").on('click',function () {
        layer.open({
            type: 2,
            content: '/gbassessRecords/select/selectElderly',
            area: ['800px', '600px'],
            title:'选择未入住老人',
            btn: ['确定 '],
            yes:function(index, layero){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
                var checkStatus = iframeWin.layui.table.checkStatus('mytable');
                if(checkStatus.data.length < 1 || checkStatus.data.length > 1){
                    iframeWin.layui.layer.msg("请选择一位老人");
                    return false;
                }else{//选择老人后根据老人id查询老人自理情况
                    $.ajax({
                        url:"/enterElderly/selectById",
                        type:'post',
                        dataType:'json',
                        data: "id="+checkStatus.data[0].id,
                        async: false,
                        success:function(msg){
                            if(msg.code == 200) {
                                var data = msg.data;
                                if (data.healthCondition=='1'){
                                    $("#healthCondition").val("自理老人");
                                }else if (data.healthCondition=='2') {
                                    $("#healthCondition").val("半失能老人");
                                }else if (data.healthCondition=='3') {
                                    $("#healthCondition").val("失能老人");
                                }
                            }
                        },
                        error:function(e){
                            console.log("加载失败");
                        }
                    });

                }
                var name = checkStatus.data[0].name;
                var id = checkStatus.data[0].id;
                var code = checkStatus.data[0].code;
                var idNo = checkStatus.data[0].idNo;
                $("#elderlyName").val(name);
                $("#elderlyId").val(id);
                $("#elderlyIdNo").val(idNo);
                //获取老人为付款的服务记录
                layer.close(index);
            }
        });
    });
});